package it.polimi.TravelDreamEAR.managedBeans;

import it.polimi.TravelDreamEAR.ejb.sessionBeans.*;
import it.polimi.TravelDreamEAR.ejb.sessionBeans.dto.*;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class ClienteBean {

	@EJB
	private RegistrationManager registrationManager;
	
	private ClienteDTO clienteDTO;
	
	public ClienteBean() {
		clienteDTO = new ClienteDTO();
	}
	
	public ClienteDTO getClienteDTO() {
		return clienteDTO;
	}

	public void setClienteDTO(ClienteDTO clienteDTO) {
		this.clienteDTO = clienteDTO;
	}

	public String getUsername(){
		return registrationManager.getClienteDTO().getUsername();
	}
	
	public String getNome() {
		return registrationManager.getClienteDTO().getNome();
	}
	
	public String getCognome() {
		return registrationManager.getClienteDTO().getCognome();
	}
	
	public String getEmail() {
		return registrationManager.getClienteDTO().getEmail();
	}
	
	public String getTelefono() {
		return registrationManager.getClienteDTO().getTelefono();
	}
	
	public String getCitta() {
		return registrationManager.getClienteDTO().getCitta();
	}
	
	public String aggiorna() {
		if(this.clienteDTO.getUsername().equals(registrationManager.getClienteDTO().getUsername())) {
			registrationManager.update(this.clienteDTO);
			return "paginaPersonaleCliente?faces-redirect=true";
		}
		else
			return "datiPersonali?faces_redirect=true";
		
	}
	
}
